var ns, toast, UIActionProgress;
var app = new Vue({
    el: '#app',
    data: {
        companyName: '', //公司名称
        postionName: "", //岗位
        userHeadImg: "", //用户头像
        userName: "", //用户名称
        bannerimg: '../image/header_bg.png',
        notice_msg: '',
        tongzhilist: [],
        form: {
            pageindex: 0,
            pagesize: 2,
        },
        current_item_length: 0,
        is_searching: false,
        can_scroll: false,
        isRead: true,
        notifyTimeOut: null,
        Status: '',
        is_scrolled: false,
        newlist: [{
            id: 1,
            type: 0,
            typename: '全员',
            list: []
        }, {
            id: 2,
            type: 1,
            typename: '工程',
            list: []
        }, {
            id: 3,
            type: 2,
            typename: '客服',
            list: []
        }, {
            id: 4,
            type: 3,
            typename: '安防',
            list: []
        }, {
            id: 5,
            type: 4,
            typename: '多种经营',
            list: []
        }, {
            id: 6,
            type: 5,
            typename: '保洁绿化',
            list: []
        }, {
            id: 7,
            type: 6,
            typename: '统计',
            list: []
        }, ],
        list: [{
            "id": 686,
            "name": "楼宇管家",
            "url": "chooseproject_frm",
            "css": "icon_sfgl",
            "count": 0,
            "type": 0,
            "fromtype": 4,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 2
        }, {
            "id": 687,
            "name": "公表抄表",
            "url": "chooseproject_frm",
            "css": "icon_gbdj",
            "count": 0,
            "type": 2,
            "fromtype": 2,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 1
        }, {
            "id": 688,
            "name": "总表抄表",
            "url": "chooseproject_frm",
            "css": "icon_zbdj",
            "count": 0,
            "type": 3,
            "fromtype": 3,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 1
        }, {
            "id": 689,
            "name": "水电抄表",
            "url": "chooseproject_frm",
            "css": "icon_sbdj",
            "count": 0,
            "type": 0,
            "fromtype": 1,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 1
        }, {
            "id": 1533,
            "name": "多次抄表",
            "url": "meterwritemultiple_more",
            "css": "icon_sbdj",
            "count": 0,
            "type": 0,
            "fromtype": 1,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 1
        }, {
            "id": 690,
            "name": "设备巡检",
            "url": "equipment_frm",
            "css": "icon_sbxj",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 1
        }, {
            "id": 691,
            "name": "内部报事",
            "url": "neibubaoshi_add_frm",
            "css": "icon_nbbx",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 0
        }, {
            "id": 692,
            "name": "安防巡更",
            "url": "patrolplan_frm",
            "css": "icon_afxg",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 3
        }, {
            "id": 693,
            "name": "保洁绿化",
            "url": "bjlh_frm",
            "css": "icon_bjlh",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 5
        }, {
            "id": 694,
            "name": "门岗管理",
            "url": "gate_sentry_frm",
            "css": "icon_mggl",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 3
        }, {
            "id": 695,
            "name": "投诉建议",
            "url": "customerservicelist_frm",
            "css": "icon_tsjy",
            "count": 0,
            "type": 2,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 2
        }, {
            "id": 696,
            "name": "新增整改工单",
            "url": "qualitycontrol_frm",
            "css": "icon_pkgl",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 2
        }, {
            "id": 1015,
            "name": "品质检查",
            "url": "qualitycontrollist_frm",
            "css": "icon_pzjc",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 2
        }, {
            "id": 813,
            "name": "管家名片",
            "url": "guanjiaCar_frm",
            "css": "icon_gjmp",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 2
        }, {
            "id": 814,
            "name": "客服工单",
            "url": "customerservicelist_frm",
            "css": "icon_kfgd",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 1
        }, {
            "id": 815,
            "name": "通讯录",
            "url": "organization_frm",
            "css": "icon_txl",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 0

        }, {
            "id": 816,
            "name": "财务统计",
            "url": "analysis_historyfeelist_frm",
            // "url": "analysis_historyfeesummary_frm",
            "css": "icon_cwtongji",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 6

        }, {
            "id": 817,
            "name": "党建学习",
            "url": "outside_study_frm",
            "css": "icon_tongji",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 0
        }, {
            "id": 956,
            "name": "审批中心",
            "url": "examine_list",
            "css": "icon_spzx",
            "count": 0,
            "type": 0,
            "isshow": false,
            // "bg": "#289FFF",
            // "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 0

        }, {
            "id": 957,
            "name": "采购申请",
            "url": "purchase_add",
            "css": "icon_cgsq",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 0
        }, {
            "id": 1064,
            "name": "内部通知",
            "url": "neibutz_list",
            "css": "icon_nebutz",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 0
        }, {
            "id": 1564,
            "name": "工作任务",
            "url": "worktasklist_frm",
            "css": "icon_gzrw",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 0
        }, {
            "id": 986,
            "name": "客服工单统计",
            "url": "analysis_customerservice_summary_frm",
            "css": "icon_tongji",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 6

        }, {
            "id": 987,
            "name": "放行条",
            "url": "outdoor_listfrm",
            "css": "icon_fxt",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 2

        }, {
            "id": 994,
            "name": "装修管理",
            "url": "zhuangxiu_frm",
            "css": "icon_zxgl",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 2
        }, {
            "id": 995,
            "name": "设备作业统计",
            // "url": "analysis_equipment_frm",
            "url": "analysis_equipments_frm",
            "css": "icon_sbtj",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 6
        }, {
            "id": 996,
            "name": "安防巡更统计",
            // "url": "analysis_equipment_frm",
            "url": "analysis_patrolplan_frm",
            "css": "icon_aftj",
            "count": 0,
            "type": 1,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 6
        }, {
            "id": 997,
            "name": "环境保洁统计",
            "url": "analysis_bjlh_frm",
            "css": "icon_bjtj",
            "count": 0,
            "type": 2,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 6
        }, {
            "id": 999,
            "name": "配送中心",
            "url": "distribution_center_frm",
            "css": "icon_pszx",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 4
        }, {
            "id": 1230,
            "name": "订单中心",
            "url": "home_orderlist_frm",
            "css": "icon_ddzx",
            "count": 0,
            "type": 0,
            "isshow": false,
            // "bg": "#289FFF",
            // "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 4
        }, {
            "id": 1016,
            "name": "品质考核",
            "url": "qualitycheck_frm",
            "css": "icon_pzkh",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 2
        }, {
            "id": 697,
            "name": "整改任务",
            "url": "qualitycontrol_mainlist",
            "css": "icon_zggd",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 2
        }, {
            "id": 1545,
            "name": "设备维修",
            "url": "repairadd_frm",
            "css": "icon_sbwe",
            "count": 0,
            "type": 0,
            "isshow": false,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
            "IsAuthority": false,
            "fenlei": 2
        }, {
            "id": 1544,
            "name": "维修工单",
            "url": "repairlist_frm",
            "css": "icon_wxgd",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 2,
            // "bg": "#289FFF",
            // "txtcolor": "#ffffff",
        }, {
            "id": 1017,
            "name": "品质管控",
            "url": "quality_analysis",
            "css": "icon_pzgk",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 6
                // "bg": "#289FFF",
                // "txtcolor": "#ffffff",
        }, {
            "id": 1042,
            "name": "服务卡",
            "url": "service_card",
            "css": "icon_pzgk",
            "count": 0,
            "type": 0,
            "isshow": false,
            "IsAuthority": false,
            "fenlei": 4,
            "bg": "#289FFF",
            "txtcolor": "#ffffff",
        }],
        summary: {
            feeSummary: {},
            projectFeeList: [],
            serviceSummary: {}
        },
        scrollInterval: {
            projectInterval: null,
            msgInterval: null,
            is_scrolled: false
        },
        canViewFeeAnalysis: false,
        canViewServiceAnalysis: false,
        isedit: false,
        //我的常用
        my_use: [

        ],
        //是否在我的常用中
        isuse: false
    },
    methods: {
        // openSetting: function () {
        //     ns.openWin('xitongshezhi_frm', '系统设置');
        // },
        // setStyle: function() {
        //     var that = this;
        //     var width = $api.offset($api.byId('cycle_container')).w;
        //     $api.css($api.byId('cycle_box'), 'width:' + width + 'px;height:' + width + 'px');
        // },
        get_data: function() {
            var that = this;
            var options = {};
            options.action = "getnewmenulist";
            toast.loading({
                title: "加载中",
                duration: 2000
            }, function(ret) {});
            ns.post(options, function(succeed, data, err) {
                toast.hide();
                setTimeout(function() {
                    that.get_data_count();
                    that.get_myuse_data();
                }, 100);
                if (succeed) {
                    that.canViewFeeAnalysis = data.canViewFeeAnalysis;
                    that.canViewServiceAnalysis = data.canViewServiceAnalysis;
                    if (data.postionName) that.postionName = data.postionName;
                    if (that.canViewServiceAnalysis) {
                        // setTimeout(function() {
                        //     app.setStyle();
                        // }, 200)
                    }
                    for (var i = 0; i < that.list.length; i++) {
                        var item = that.list[i];
                        for (var j = 0; j < data.list.length; j++) {
                            var item2 = data.list[j];
                            if (item2.id == item.id) {
                                item.isshow = item2.isshow;
                                break;
                            }
                        }
                    }

                    // 分类
                    that.newlist.forEach((newitem) => {
                        newitem.list = [];
                        that.list.forEach((item) => {
                            if (newitem.type == item.fenlei && item.isshow == true) {
                                newitem.list.push(item);
                            }
                        });
                    });
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        get_data_count: function() {
            var that = this;
            var options = {};
            options.action = "getmenucountlist";
            ns.post(options, function(succeed, data, err) {
                setTimeout(function() {
                    that.getAnalysisData();
                }, 100);
                if (succeed) {
                    for (var i = 0; i < that.list.length; i++) {
                        if (that.list[i].name == '设备巡检') {
                            that.list[i].count = data.countform.DeviceTaskCount;
                        }
                        if (that.list[i].name == '安防巡更') {
                            that.list[i].count = data.countform.PatrolTaskCount;
                        }
                        if (that.list[i].name == '保洁绿化') {
                            that.list[i].count = data.countform.EventTaskCount;
                        }
                        if (that.list[i].name == '投诉建议') {
                            that.list[i].count = data.countform.SuggestionCount;
                        }
                        if (that.list[i].name == '整改任务') {
                            that.list[i].count = data.countform.QualityCount;
                        }
                        if (that.list[i].name == '客服工单') {
                            that.list[i].count = data.countform.CustomerCount;
                        }
                        if (that.list[i].name == '审批中心') {
                            that.list[i].count = data.countform.ApprovalCenterCount;
                        }
                        if (that.list[i].name == '放行条') {
                            that.list[i].count = data.countform.ReleaseNoReadCount;
                        }
                        if (that.list[i].name == '品质检查') {
                            that.list[i].count = data.countform.CheckQualityCount;
                        }
                        if (that.list[i].name == '品质考核') {
                            that.list[i].count = data.countform.KHQualityCount;
                        }
                        if (that.list[i].name == '维修工单') {
                            that.list[i].count = data.countform.DeviceServiceCount;
                        }
                    }
                    api.sendEvent({
                        name: 'isAllNumber',
                        extra: {
                            AllCount: data.countform.AllCount
                        }
                    });
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        get_myuse_data: function() {
            var that = this
            var options = {};
            options.action = "getsysmenuidmodulelist";
            ns.post(options, function(succeed, data, err) {
                if (succeed) {
                    that.my_use = []
                    for (var i = 0; i < data.data.length; i++) {
                        var item = data.data[i]
                        for (var j = 0; j < that.list.length; j++) {
                            var item2 = that.list[j]
                            if (item2.id == item.ID) {
                                that.isuse = true
                                item2.IsAuthority = item.IsAuthority
                                that.my_use.push(item2)
                            }
                        }
                    }
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        openWin: function(item, params) {
            var that = this;
            if (item.url == '') {
                return;
            }
            params = params || {
                status: -1,
                servicetype: item.type,
                metertype: item.type,
                fromtype: item.fromtype || 0,
                selecttype: 2,
                bg: item.bg,
                txtcolor: item.txtcolor,
            };
            ns.openWin(item.url, item.name, params);
        },
        // open_tongzhixiaoxi: function () {
        //     ns.openWin('tongzhixiaoxi_frm', '通知公告');
        // },
        // open_gonggao_detail: function (id, title) {
        //     var that = this;
        //     ns.openWin('tongzhixiaoxidetail_frm', '通知公告', {
        //         id: id
        //     }, {
        //         needlogin: true
        //     });
        //     api.sendEvent({
        //         name: 'isreadtrue',
        //         extra: {
        //             key1: 'value1'
        //         }
        //     });
        // },
        // get_gonggao: function () {
        //     var that = this;
        //     that.is_searching = true;
        //     that.can_scroll = false;
        //     var options = {};
        //     options.pageindex = that.form.pageindex;
        //     options.pagesize = that.form.pagesize;
        //     options.action = "getmsglist";
        //     ns.post(options, function (succeed, data, err) {
        //         setTimeout(function () {
        //             that.get_data_count();
        //         }, 300);
        //         that.is_searching = false;
        //         if (succeed) {
        //             that.tongzhilist = data.tongzhilist;
        //             if (that.tongzhilist.length > 0) {
        //                 setTimeout(function () {
        //                     that.init_sroll('scrollmsgbox', 'scrollmsg');
        //                 }, 1000)
        //             }
        //         } else if (err) {
        //             that.current_item_length = 0;
        //             api.toast({
        //                 msg: err,
        //                 duration: 2000,
        //                 location: 'bottom'
        //             });
        //         }
        //     });
        // },
        // init_sroll: function (scrollElemID, leftElemID) {
        //     var that = this;
        //     var scrollOption = {};
        //     var scrollElem = $api.byId(scrollElemID);

        //     if (that.scrollInterval.is_scrolled) {
        //         var childNodes = scrollElem.childNodes;
        //         for (var i = 0; i < childNodes.length; i++) {
        //             $api.remove(childNodes[i]);
        //         }
        //         if (scrollElemID == 'scrollmsgbox') {
        //             if (that.scrollInterval.msgInterval) {
        //                 clearInterval(that.scrollInterval.msgInterval);
        //                 that.scrollInterval.msgInterval = null;
        //             }
        //         }
        //         if (scrollElemID == 'scrollprojectbox') {
        //             if (that.scrollInterval.projectInterval) {
        //                 clearInterval(that.scrollInterval.projectInterval);
        //                 that.scrollInterval.projectInterval = null;
        //             }
        //         }
        //     }
        //     that.scrollInterval.is_scrolled = true;
        //     try {
        //         // scrollElem = document.getElementById("scrolllayer");
        //         with (scrollElem) {
        //             style.width = 500; //宽度
        //             noWrap = true;
        //         }
        //         scrollOption.preTop = 0;
        //         scrollOption.currentTop = 0;
        //         scrollOption.stoptime = 0;
        //         scrollOption.scrollCount = 0;
        //         // var leftElem = document.getElementById('scrollmessage');
        //         var leftElem = $api.byId(leftElemID);
        //         var childNodes = leftElem.childNodes;
        //         for (var i = 0; i < 2; i++) {
        //             for (var j = 0; j < childNodes.length; j++) {
        //                 scrollElem.appendChild(childNodes[j].cloneNode(true));
        //             }
        //         }
        //         // scrollElem.appendChild(leftElem.cloneNode(true));
        //         var elems = document.getElementsByName('notify_item');
        //         for (var i = 0; i < elems.length; i++) {
        //             elems[i].onclick = function () {
        //                 var id = $api.attr(this, 'data-id');
        //                 if (scrollElemID == 'scrollmsgbox') {
        //                     that.open_gonggao_detail(id);
        //                 }
        //             };
        //         }
        //     } catch (e) { }
        //     scrollElem.scrollTop = 0;
        //     if (scrollElemID == 'scrollmsgbox') {
        //         that.scrollInterval.msgInterval = setInterval(function () {
        //             that.scroll_up(scrollElemID, leftElemID, scrollOption);
        //         }, 15); //滚动速度
        //     } else if (scrollElemID == 'scrollprojectbox') {
        //         that.scrollInterval.projectInterval = setInterval(function () {
        //             that.scroll_up(scrollElemID, leftElemID, scrollOption);
        //         }, 15); //滚动速度
        //     }
        // },
        // scroll_up: function (scrollElemID, leftElemID, scrollOption) {
        //     var that = this;
        //     var scrollElem = $api.byId(scrollElemID);
        //     scrollOption.currentTop += 1;
        //     if (scrollOption.currentTop == 56) { //滚动距离
        //         scrollOption.stoptime += 1;
        //         scrollOption.currentTop -= 1;
        //         if (scrollOption.stoptime == 300) { //停顿时间
        //             scrollOption.currentTop = 0;
        //             scrollOption.stoptime = 0;
        //             scrollOption.scrollCount++;
        //             if (scrollOption.scrollCount >= 10) {
        //                 that.init_sroll(scrollElemID, leftElemID);
        //             }
        //         }
        //     } else {
        //         scrollOption.preTop = scrollElem.scrollTop;
        //         scrollElem.scrollTop += 1;
        //         if (scrollOption.preTop == scrollElem.scrollTop) {
        //             scrollElem.scrollTop = 0;
        //             scrollElem.scrollTop += 1;
        //         }
        //     }
        // },
        get_user_data: function() {
            var that = this;
            // 公司名称
            var companyName = api.getPrefs({
                sync: true,
                key: 'companyName'
            });
            // 岗位名称
            var positionname = api.getPrefs({
                sync: true,
                key: 'positionname'
            });
            // 用户名称
            var username = api.getPrefs({
                sync: true,
                key: 'username'
            });
            // 用户头像
            var headimg = api.getPrefs({
                sync: true,
                key: 'headimg'
            });
            that.companyName = companyName || '重庆永友网络科技有限公司';
            that.postionName = positionname ? positionname : "";
            // that.userHeadImg = headimg || '../image/default.png';
            that.userHeadImg = '../image/default.png';
            that.userName = username || '匿名用户';
        },
        do_open_scan_login: function(item) {
            var that = this;
            ns.confirmPer('camera', function() {
                setTimeout(function() {
                    that.do_open_scan_login_start();
                }, 200)
            })
        },
        do_open_scan_login_start: function() {
            var that = this;
            ns.openFrame('scanner_frm', {
                type: 0
            });
        },
        // doOpenFeeSummary: function() {
        //     ns.openWin('analysis_historyfeesummary_frm', '收费统计');
        // },
        doOpenFeeList: function(type) {
            ns.openWin('analysis_historyfeelist_frm', '收支流水', {
                type: type
            });
        },
        doOpenServiceSummary: function(type) {
            ns.openWin('analysis_customerservice_summary_frm', '客服工单统计', {
                "bg": "#289FFF",
                "txtcolor": "#ffffff"
            });
        },
        // doOpenServiceList: function(type) {
        //     ns.openWin('customerservicelist_tongji', '客服工单统计', {
        //         isviewdetail: true,
        //         "bg":"#289FFF",
        //         "txtcolor":"#ffffff"
        //     });
        // },
        getAnalysisData: function() {
            var that = this;
            if (!that.canViewFeeAnalysis && !that.canViewServiceAnalysis) {
                return;
            }
            var options = {
                action: 'gethomeanalysisdata'
            };
            ns.post(options, function(succeed, data, err) {
                if (succeed) {
                    that.summary = data;
                    if (that.summary.projectFeeList && that.summary.projectFeeList.length > 0) {
                        setTimeout(function() {
                            that.init_sroll('scrollprojectbox', 'scrollprojectmsg');
                        }, 3000)
                    }
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        // 打开个人中心
        openSetting: function() {
            ns.openWin('gerenzhongxin_frm', '个人信息');
        },
        do_edit: function() {
            var that = this;
            that.isedit = !that.isedit;
            if (that.isedit == false) {
                var sss = []
                that.my_use.forEach(function(item) {
                    if (item.IsAuthority == true) {
                        sss.push(item.id)
                    }
                })
                var options = {}
                options.action = 'savecommonmodule';
                options.SysMenuIds = JSON.stringify(sss)
                    // console.log(JSON.stringify(sss))
                ns.post(options, function(succeed, data, err) {
                    if (succeed) {
                        api.toast({
                            msg: '保存成功',
                            duration: 2000,
                            location: 'bottom'
                        });
                    } else if (err) {
                        api.toast({
                            msg: err,
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                }, {
                    toast: true
                });
            }

        },
        //添加我的常用
        add_my_use: function(item) {
            var that = this;
            that.isuse = true
            var myuse = {}
            Object.assign(myuse, item)
            if (myuse.id == item.id) {
                item.IsAuthority = true
                myuse.IsAuthority = item.IsAuthority

            }
            that.my_use.push(myuse)
        },
        //删除我的常用
        delete_my_use: function(item) {
            var that = this;
            item.IsAuthority = false
            for (i = 0; i < that.list.length; i++) {
                if (item.id == that.list[i].id) {
                    that.list[i].IsAuthority = item.IsAuthority
                }
            }
            for (var i = 0; i < that.my_use.length; i++) {
                var item2 = that.my_use[i]
                if (item2.id == item.id) {
                    that.my_use.splice(i, 1)
                }
            }
            if (that.my_use.length == 0) {
                that.isuse = false
            }
        },
        save_jiguang_register_id: function() {
            var that = this;
            var deviceId = api.getPrefs({
                sync: true,
                key: 'jpush_device_id'
            })
            if (deviceId) {
                ns.post({
                    action: 'savedeviceid',
                    device_id: deviceId,
                    device_type: api.systemType
                }, function(succeed, data, err) {
                    console.log(err)
                });
            }
        }
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    UIActionProgress = api.require('UIActionProgress');
    toast = new auiToast();
    app.get_data();
    // app.getAnalysisData();
    setTimeout(function() {
        appupgrade.check_upgrade(false);
    }, 5000)
    setTimeout(function() {
        app.save_jiguang_register_id();
    }, 1000)
    ns.init_pull(true);
    app.get_user_data();
    api.addEventListener({
        name: 'changecentersuccess'
    }, function() {
        app.get_user_data();
    });
    api.addEventListener({
        name: 'home_new_updata'
    }, function() {
        app.get_data_count();
    });
    api.addEventListener({
        name: 'purchase_updata'
    }, function() {
        app.get_data_count();
    });
    api.addEventListener({
        name: 'reload_Analysis'
    }, function() {
        app.getAnalysisData();
    });
    api.addEventListener({
        name: 'reloadservicelist'
    }, function(ret, err) {
        app.get_data_count();
    });
    api.addEventListener({
        name: 'isreadtrue'
    }, function(ret, err) {
        if (ret) {
            setTimeout(function() {
                app.get_data();
            }, 500);
        } else {
            api.toast({
                msg: err,
                duration: 2000,
                location: 'bottom'
            });
        }
    });
}
